<template>
    <div class="mod-prod-prodTag">
        <avue-crud ref="crud"
                   :page="page"
                   :data="dataList"
                   :table-loading="dataListLoading"
                   :option="tableOption"
		
                   @search-change="searchChange"
                   @on-load="getDataList"
                   @refresh-change="refreshChange"
                   @row-update="addUpdate"
                   @row-save="rowSave">
            <!-- <template slot-scope="scope"
                      slot="menu">
                <el-button type="text" size="mini" icon="el-icon-search" @click="openOldYears(scope.row)">历年查询</el-button>
            </template> -->
        </avue-crud>
        <old-years ref="oldYearsRef"></old-years>
    </div>
</template>

<script>
import OldYears from './OldYears.vue'
import { tableOption } from '@/crud/manage/company'
export default {
	components: {
		OldYears
	},
	data () {
		return {
			page: {
				total: 0, // 总页数
				currentPage: 1, // 当前页数
				pageSize: 10 // 每页显示多少条
			},
			dataList: [
				// { custom: "客户1",dept:"销售一部",man:"张三", id: 1, type: 0, "1": 10000, year: "2025",
				// },
				// { custom: "客户2", type: 0 },
				// { custom: "客户3", type: 0 },
			],
			dataListLoading: false,
			tableOption: tableOption,
			permission: {
				delBtn: this.isAuth('prod:prodTag:delete')
			},
		}
	},
	created () {
	},
	mounted () {
        this.initSelectData()
	},
	methods: {
        initSelectData(){
            this.$http({
                url: this.$http.adornUrl('/crm/base/emp/page'),
                method: 'get',
                params: this.$http.adornParams(Object.assign({
                    current: 1,
                    size: 100
                }, {}))
            }).then(({data}) => {
                console.log('🚀 ~ data', data.obj.records)
                const targetColumn = this.tableOption.column.find((col) => {
                    return col.prop === "deptEmpNo"
                });
                this.$set(targetColumn, 'dicData', data.obj.records);
            })
        },
		openOldYears(){
			this.$refs.oldYearsRef.init()
		},
		getDataList (page, params, done) {
            // this.$refs.crud.dicInit()
			this.dataListLoading = true
			this.$http({
				url: this.$http.adornUrl('/crm/year/plan/page'),
				method: 'get',
				params: this.$http.adornParams(Object.assign({
					current: page == null ? this.page.currentPage : page.currentPage,
					size: page == null ? this.page.pageSize : page.pageSize
				}, {
                    planType: 0,
					...params
                }))
			}).then(({ data }) => {
				this.dataList = data.obj.records
                console.log('🚀 ~ this.dataList', this.dataList)
				this.page.total = data.obj.total
				this.dataListLoading = false
				if (done) {
					done()
				}
			})
		},
        rowSave (form, done, loading) {
            console.log('🚀 ~ form', form)
            this.$http({
                url: this.$http.adornUrl('/crm/year/plan/addPlanDept'),
                method: 'post',
                data: this.$http.adornData({
                    ...form,
                    planType: 0
                })
            }).then(({data}) => {
                this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                        if (done) {
                            done()
                        }
                        this.getDataList(this.page)
                    }
                })
            })
        },
        addUpdate(){
        
        },
		// 新增 / 修改
		addOrUpdateHandle (id) {
			this.addOrUpdateVisible = true
			this.$nextTick(() => {
				this.$refs.addOrUpdate.init(id)
			})
		},
		deleteHandle (id) {
			this.$confirm('确定进行删除操作?', '友情提醒', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$http({
					url: this.$http.adornUrl('/prod/prodTag/' + id),
					method: 'delete',
					data: this.$http.adornData({})
				}).then(({ data }) => {
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.getDataList(this.page)
						}
					})
				})
			}).catch(() => { })
		},
		/**
		 * 刷新回调
		 */
		refreshChange () {
			this.getDataList(this.page)
		},
		searchChange (params, done) {
			this.getDataList(this.page, params, done)
		}
	}
}
</script>

<style lang="scss" scoped>
</style>
